package com.yuwenxin.dao.impl;

import com.yuwenxin.bean.MusicList;
import com.yuwenxin.bean.User;
import com.yuwenxin.core.BaseDaoImpl;
import com.yuwenxin.core.BaseQueryModel;
import com.yuwenxin.dao.MusicListDao;
import com.yuwenxin.dao.UserDao;

import java.sql.ResultSet;

public class MusicListDaoImpl extends BaseDaoImpl implements MusicListDao {
    @Override
    public String getSelectAllSql() {
        return "select * from musiclist";
    }

    @Override
    public String getSelectByNameSql() {
        return "select * from musiclist where musiclistName = ?";
    }

    @Override
    public String getFuzzyFindSql() {
        return "select * from musiclist where musiclistName like ?";
    }

    @Override
    public String getUpdateSql(Object object) {
        return null;
    }

    @Override
    public String getDeleteSql() {
        return "delete from musiclist where idmusiclist = ?";
    }

    @Override
    public String getSelectByIdSql() {
        return "select * from musiclist where idmusiclist = ?";
    }

    @Override
    public String getInsertSql(Object object) {
        MusicList _musicList = (MusicList) object;
        String musiclistName = _musicList.getMusiclistName();
        //noinspection UnnecessaryLocalVariable，这里取消了对musiclistPhotoPath的警告
        String musiclistPhotoPath = MusicListDao.DEFAULT_PATH;
        int relativeUserid = _musicList.getRelativeUserId();
        return "insert into musiclist (musiclistName,musiclistPhotoPath,relativeUserid) values ("
                + musiclistName + "','" + musiclistPhotoPath + "','" + relativeUserid + ")";
    }

    @Override
    public String getConditionSql(BaseQueryModel queryModel) {
        return null;
    }

    @Override
    public Object toEntity(ResultSet rs) throws Exception {
        MusicList musicList = new MusicList();

        UserDao userDao = new UserDaoImpl();

        musicList.setId(rs.getInt("idmusiclist"));
        musicList.setMusiclistName(rs.getString("musiclistName"));
        musicList.setMusiclistPhotoPath(rs.getString("musiclistPhotoPath"));
        musicList.setRelativeUserId(rs.getInt("relativeUserid"));
        musicList.setRelativeUser((User) userDao.find(rs.getInt("relativeUserid")));

        return null;
    }
}
